<?php

namespace app\payment\model;

use app\payment\model\App as AppModel;
use think\Model;

/**
 * 订单模型
 */
class Order extends Model {

    // 设置当前模型对应的完整数据表名称
    protected $name = 'payment_order';
    // 主键
    protected $pk = 'order_id';
    // 自动写入时间戳
    protected $autoWriteTimestamp = false;

    /**
     * 获取应用名称
     * @param  array $app_id 应用id
     * @return mixed
     */
    public static function appName($app_id = '') {
        return AppModel::where(['id' => $app_id])->value('app_name');
    }

    /**
     * 获取应用id和名称
     * @param  array   $merchant_id 应用id
     * @param  boolean $class       类型
     * @return mixed
     */
    public static function appidName($merchant_id = '', $class = false) {
        $map = $merchant_id ? ['merchant_id' => $merchant_id] : [];
        if ($class) {
            $res = AppModel::where($map)->column('app_name,merchant_id', 'id');
            if ($res) {
                foreach ($res as $key => $value) {
                    $res[$key] = $value['merchant_id'] . '—>' . $value['app_name'];
                }
            }
        } else {
            $res = AppModel::where($map)->column('app_name', 'id');
        }
        return $res;
    }

}
